package com.module;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import com.valuebean.ADOrder;

import DateBase.Datebase;

public class ADOrderModule {
	Datebase con=new Datebase();
	Connection conn=(Connection) con.getConnection();
	public ArrayList selectMsg() throws SQLException{
		String sql="select * from ordermsg";
		Statement st=(Statement) conn.createStatement();
		ResultSet rs=st.executeQuery(sql);
		ArrayList list = new ArrayList();
		while(rs.next()){
			ADOrder o=new ADOrder();
			o.setOrderid(rs.getInt("orderid"));
			o.setOrdernum(rs.getInt("ordernum"));
			o.setOrdertime(rs.getString("ordertime"));
			o.setPrice(rs.getFloat("price"));
			o.setSta(rs.getInt("sta"));
			o.setUserid(rs.getInt("userid"));
			list.add(o);
		}
		return list;
	}
	public int delAction(int orderid) throws SQLException{
		String sql="delete from ordermsg where orderid="+orderid+"";
		Statement st=(Statement) conn.createStatement();
		int flag=st.executeUpdate(sql);
		if(flag==1)
			return 1;
		else
			return 0;
	}
	
	public int updateAction(int sta,int orderid) throws SQLException{
		String sql="update ordermsg set sta ="+sta+" where orderid = "+orderid+"";
		System.out.print(sql);
		Statement st=(Statement) conn.createStatement();
		int flag=st.executeUpdate(sql);
		if(flag==1)
			return 1;
		else
			return 0;
	}
	
	
}
